package format

import (
	"gitee.com/general252/gortc/pkg/format/codec"
	"gitee.com/general252/gortc/pkg/format/rtpencoder"
	"github.com/bluenviron/gortsplib/v4/pkg/format"
)

type PS struct {
	format.Generic
}

func NewPS(generic format.Generic) *PS {
	return &PS{
		Generic: generic,
	}
}

// Codec implements Format.
func (f *PS) Codec() string {
	return "PS"
}

// CreateDecoder creates a decoder able to decode the content of the format.
func (f *PS) CreateDecoder() (*rtpencoder.PSRtpDecoder, error) {
	d := &rtpencoder.PSRtpDecoder{}

	err := d.Init()
	if err != nil {
		return nil, err
	}

	return d, nil
}

// CreateEncoder creates an encoder able to encode the content of the format.
func (f *PS) CreateEncoder() (*rtpencoder.PSRtpEncoder, error) {
	e := &rtpencoder.PSRtpEncoder{
		PayloadType: f.PayloadType(),
		Codecs: []codec.CodecId{
			codec.H264, codec.H265,
			codec.AAC, codec.G711A, codec.G711U,
		},
	}

	err := e.Init()
	if err != nil {
		return nil, err
	}

	return e, nil
}
